/**
 *  mLasq.cpp
 *
 *  Copyright (C) 2008  David Andrs <pda@jasnapaka.com>
 *
 *  This program is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation, either version 2 of the License, or
 *  (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *
 */

#include "StdAfx.h"
#include "mLasq.h"

#include "MainFrm.h"
#include "ctrls/LinkCtrl.h"
#include "Config.h"

#include "ctrls/CePropertySheet.h"
#include "AboutPg.h"
#include "LicensePg.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CMLasqApp

BEGIN_MESSAGE_MAP(CMLasqApp, CWinApp)
	//{{AFX_MSG_MAP(CMLasqApp)
	ON_COMMAND(ID_APP_ABOUT, OnAppAbout)
	//}}AFX_MSG_MAP
	// Standard file based document commands
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CMLasqApp construction

CMLasqApp::CMLasqApp()
	: CWinApp()
{
}

/////////////////////////////////////////////////////////////////////////////
// The one and only CMLasqApp object

CMLasqApp theApp;

/////////////////////////////////////////////////////////////////////////////
// CMLasqApp initialization

BOOL CMLasqApp::InitInstance()
{
	// Standard initialization
	HIDPI_InitScaling();
	InitCommonControls();

	// init win sock
	WSADATA wsaData;
	WSAStartup(0x0101, &wsaData);

	//
	Config.Load();

#ifdef LOGGING
	Logger = new CLogger(Config.LogFile, Config.LogLevel);
#endif

	// Change the registry key under which our settings are stored.
	SetRegistryKey(_T("DaProfik"));

	CMainFrame* pFrame = new CMainFrame;
	m_pMainWnd = pFrame;

	// create and load the frame with its resources

	pFrame->LoadFrame(IDR_MAINFRAME,
		WS_OVERLAPPEDWINDOW | FWS_ADDTOTITLE, NULL,
		NULL);


	pFrame->ShowWindow(m_nCmdShow);
	pFrame->UpdateWindow();

	return TRUE;
}

int CMLasqApp::ExitInstance() {
	Config.Save();

	WSACleanup();

#ifdef LOGGING
	delete Logger;
#endif

	return CWinApp::ExitInstance();
}

/////////////////////////////////////////////////////////////////////////////
// CMLasqApp message handlers


// App command to run the dialog
void CMLasqApp::OnAppAbout()
{
	CAboutPg pgAbout;
	CLicensePg pgLicense;

	CCePropertySheet sheet(IDS_ABOUT);
	sheet.AddPage(&pgAbout);
	sheet.AddPage(&pgLicense);
	sheet.SetMenu(IDR_CANCEL);
	sheet.DoModal();
}

